import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    userInfo: null,
    token: '',
    points: 0
  }),
  
  actions: {
    setUserInfo(info) {
      this.userInfo = info
      if (info && info.point) {
        this.points = info.point
      }
    },
    setToken(token) {
      this.token = token
    },
    updatePoints(points) {
      this.points = points
      if (this.userInfo) {
        this.userInfo.point = points
      }
    },
    logout() {
      this.userInfo = null
      this.token = ''
      this.points = 0
    }
  }
}) 